<?php
abstract class RecordObject{
	abstract public static function getTableName();

	private $_new;

	public function __construct($new = true) {
		$this->_new = $new;
	}

	public function isNew() {
		return $this->_new;
	}

	public function addValueToJsonArray($field_name, $value) {
		$object = json_decode(@$this->$field_name, true);

		if (is_null($object)) {
			$object = array();
		}
		
		if (!is_array($object)) {
			$object = array($object);
		}
		
		if (@!in_array($value, $object)) {
			$object[] = $value;
		}

		$this->$field_name = json_encode($object);

		return TRUE;
	}
	
	public function addValueToJsonHash($field_name, $key, $value) {
		$object = json_decode(@$this->$field_name);
		
		if (is_null($object)) {
			$object = array();
		}
		
		$thing = $object->$key;
		if (is_null($thing)) {
			$thing = array();
		}
		
		if (@!in_array($value, $thing)) {
			$thing[] = $value;
		}

		$object->$key = $thing;
		$this->$field_name = json_encode($object);

		return TRUE;
	}	

	public function addHashToJsonHash($field_name, array $value) {
		$object = json_decode(@$this->$field_name, true);

		if (is_null($object)) {
			$object = array();
		}
		
		foreach ($value as $k => $v) {
			$object[$k] = $v;
		}

		$this->$field_name = json_encode($object);

		return TRUE;
	}

	public function getPrimaryKey() {
		return array('id');
	}
}

?>